package com.zhouxiaoge.内部类;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-05-03 17:34
 */

public class LocalInnerClassTest {
    public static void main(String[] args) {
        LocalTalkingClock localTalkingClock = new LocalTalkingClock();
        localTalkingClock.start(1000, true);
        JOptionPane.showMessageDialog(null, "退出");
        System.exit(0);
    }
}

class LocalTalkingClock {
    public void start(int interval, final boolean beep) {
        class Timeprinter implements ActionListener {
            @Override
            public void actionPerformed(ActionEvent e) {
                Date date = new Date();
                System.out.println("At the tone, the time is " + date);
                if (beep) {
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }
        ActionListener listener = new Timeprinter();
        Timer timer = new Timer(interval, listener);
        timer.start();
    }
}